using Godot;
using System;

public partial class Slime : Node2D
{
    private const float Speed = 60.0f;
    private int _direction = 1;
    private RayCast2D RayCastRight;
    private RayCast2D RayCastLeft;
    private AnimatedSprite2D AnimatedSprite2dNode;

    public override void _Ready()
    {
        RayCastRight = GetNode<RayCast2D>("RayCastRight");
        RayCastLeft = GetNode<RayCast2D>("RayCastLeft");
        AnimatedSprite2dNode = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
    }

    public override void _Process(double delta)
    {

        if (RayCastRight.IsColliding())
        {
            _direction = -1;
            AnimatedSprite2dNode.FlipH = true;
        }

        if (RayCastLeft.IsColliding())
        {
            _direction = 1;
            AnimatedSprite2dNode.FlipH = false;
        }
        
        Position = new(Position.X + _direction * Speed * (float)delta, Position.Y);
        
    }
}
